﻿using System;
using System.Collections.Generic;
using System.Text;
using Young3.FMSearch.Business.Managers;
using Young3.FMSearch.Business.Offsets;
using System.Linq;

namespace Young3.FMSearch.Business.Entities.InGame
{
    public class HumanManager : Staff
    {
        public HumanManager(int memoryAddress)
            : base(memoryAddress)
        { }

        public override bool isHuman
        {
            get { return true; }
        }

        public override int Age
        {
            get
            {
                return Convert.ToInt32(((Global.IngameDate - DateOfBirth)).Days / 365);
            }
        }

        public override int ID
        {
            get { return ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.Id); }
        }

        private int CityOfBirthAddress
        {
            get { return ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.CityOfBirth); }
            set { ProcessManager.WriteInt32(value, MemoryAddress + HumanManagerOffsets.CityOfBirth, false); }
        }

        public override City CityOfBirth
        {
            get { return new City(CityOfBirthAddress); }
            set { CityOfBirthAddress = value.MemoryAddress; }
        }

        public override ChairmanSkills ChairmanSkills
        {
            get { return new ChairmanSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override CoachingSkills CoachingSkills
        {
            get { return new CoachingSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override CoachMentalSkills MentalSkills
        {
            get { return new CoachMentalSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override StaffMentalTraitsSkills StaffMentalTraitsSkills
        {
            get { return new StaffMentalTraitsSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override NonTacticalSkills NonTacticalSkills
        {
            get { return new NonTacticalSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override RolesSkills RolesSkills
        {
            get { return new RolesSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.StaffRolesAddress)); }
        }

        public override CoachTacticalSkills TacticalSkills
        {
            get { return new CoachTacticalSkills(ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.SkillsAdress)); }
        }

        public override Contract Contract
        {
            get
            {
                int address = ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.ContractPointer);
                int memoryAddress = ProcessManager.ReadInt32(address);
                return new Contract(memoryAddress);
            }
        }

        public override int CurrentCoachingAbility
        {
            get { return ProcessManager.ReadInt16(MemoryAddress + HumanManagerOffsets.CurrentCoachingAbility); }
            set { ProcessManager.WriteInt16(value, MemoryAddress + HumanManagerOffsets.CurrentCoachingAbility); }
        }

        public override DateTime DateOfBirth
        {
            get { return ProcessManager.ReadDateTime(MemoryAddress + HumanManagerOffsets.DateOfBirth); }
            set { ProcessManager.WriteDateTime(value, MemoryAddress + HumanManagerOffsets.DateOfBirth); }
        }

        public override string FirstName
        {
                get { return ProcessManager.ReadString(MemoryAddress + HumanManagerOffsets.FirstName, 0x20); }
        }

        public override byte InternationalCaps
        {
            get { return ProcessManager.ReadByte(MemoryAddress + HumanManagerOffsets.InternationalCaps); }
            set { ProcessManager.WriteByte(value, MemoryAddress + HumanManagerOffsets.InternationalCaps); }
        }

        public override byte InternationalGoals
        {
            get { return ProcessManager.ReadByte(MemoryAddress + HumanManagerOffsets.InternationalGoals); }
            set { ProcessManager.WriteByte(value, MemoryAddress + HumanManagerOffsets.InternationalGoals); }
        }

        public override string LastName
        {
            get { return ProcessManager.ReadString(MemoryAddress + HumanManagerOffsets.LastName, 0x20); }
        }

        private int NationalityAddress
        {
            get { return ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.Nationality); }
            set { ProcessManager.WriteInt32(value, MemoryAddress + HumanManagerOffsets.Nationality, false); }
        }

        public override Country Nationality
        {
            get { return new Country(NationalityAddress); }
            set { NationalityAddress = value.MemoryAddress; }
        }

        public override string Nickname
        {
            get { return ProcessManager.ReadString(MemoryAddress + HumanManagerOffsets.Nickname, 0x20); }
        }

        public override int PotentialCoachingAbility
        {
            get { return ProcessManager.ReadInt16(MemoryAddress + HumanManagerOffsets.PotentialCoachingAbility); }
            set { ProcessManager.WriteInt16(value, MemoryAddress + HumanManagerOffsets.PotentialCoachingAbility); }
        }

        public override byte U21InternationalCaps
        {
            get { return ProcessManager.ReadByte(MemoryAddress + HumanManagerOffsets.U21InternationalCaps); }
            set { ProcessManager.WriteByte(value, MemoryAddress + HumanManagerOffsets.U21InternationalCaps); }
        }

        public override byte U21InternationalGoals
        {
            get { return ProcessManager.ReadByte(MemoryAddress + HumanManagerOffsets.U21InternationalGoals); }
            set { ProcessManager.WriteByte(value, MemoryAddress + HumanManagerOffsets.U21InternationalGoals); }
        }

        public override int CurrentPrestige
        {
            get { return ProcessManager.ReadInt16(MemoryAddress + HumanManagerOffsets.CurrentPrestige); }
            set { ProcessManager.WriteInt16(value, MemoryAddress + HumanManagerOffsets.CurrentPrestige); }
        }

        public override int NationalPrestige
        {
            get { return ProcessManager.ReadInt16(MemoryAddress + HumanManagerOffsets.NationalPrestige); }
            set { ProcessManager.WriteInt16(value, MemoryAddress + HumanManagerOffsets.NationalPrestige); }
        }

        public override int InternationalPrestige
        {
            get { return ProcessManager.ReadInt16(MemoryAddress + HumanManagerOffsets.InternationalPrestige); }
            set { ProcessManager.WriteInt16(value, MemoryAddress + HumanManagerOffsets.InternationalPrestige); }
        }

        private int TeamAdress
        {
            get { return ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.TeamAddress); }
        }

        private int NationalTeamAdress
        {
            get { return ProcessManager.ReadInt32(MemoryAddress + HumanManagerOffsets.NationalTeamAddress); }
        }

        public override Team Team
        {
            get { return new Team(TeamAdress); }
        }

        public override Team NationalTeam
        {
            get { return new Team(NationalTeamAdress); }
        }

        public override string ToString()
        {
            return FirstName + " " + LastName;
        }
    }
}